package cn.edu.zzuli.controller;

import cn.edu.zzuli.entity.R;
import cn.edu.zzuli.util.AliOssUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/oss")
public class ImgController {

    @Resource
    AliOssUtils ossUtils;

    @GetMapping("/get/{fileName}/{type}")
    @ApiOperation("GET请求： /ekij/jpg 获取 当前文件名的 授权访问地址(URL)。")
    public R getFileUrl(@PathVariable("fileName") String fileName,
                        @PathVariable("type") String type) {
        return R.success().add("URL", ossUtils.getUrl(fileName + "."+ type));
    }

    @PutMapping("/put/{fileName}/{type}")
    @ApiOperation("PUT请求：/ekij/jpg 获取 上传地址的url")
    public R getPutFileUrl(@PathVariable("fileName") String fileName,
                           @PathVariable("type") String type) {
        return R.success().add("URL", ossUtils.getPutUrl(fileName + "."+ type));
    }
}
